﻿using Md.Api.Model;
using Md.Api.Model.Web.MdAddress.Request;
using Md.Api.Service.Web.MdAddress;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Web;
/// <summary>
/// PC收货/发货地址管理
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/web/address")]
public class MdAddressWebController : ControllerBase
{
    /// <summary>
    /// 通过编号删除收货/发货地址服务
    /// </summary>
    public DeleteMdAddressByIdWebService deleteMdAddressByIdWebService { get; set; }
    /// <summary>
    /// 通过编号删除收货/发货地址
    /// </summary>
    /// <param name="addressIds">地址编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{addressIds}")]
    public async Task<ResponseMessageModel> DeleteMdAddressByIdWeb(string addressIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteMdAddressByIdWebModel();

        model.Ids = addressIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteMdAddressByIdWebService.Execute(model));
    }

    /// <summary>
    /// 添加收货/发货地址服务
    /// </summary>
    public InsertMdAddressWebService insertMdAddressWebService { get; set; }
    /// <summary>
    /// 添加收货/发货地址
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertMdAddressWeb([FromBody] RequestInsertMdAddressWebModel model)
    {
        return await Task.Run(() => insertMdAddressWebService.Execute(model));
    }

    /// <summary>
    /// 通过编号更新收货/发货地址服务
    /// </summary>
    public UpdateMdAddressByIdWebService updateMdAddressByIdWebService { get; set; }
    /// <summary>
    /// 通过编号更新收货/发货地址
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateMdAddressByIdWeb([FromBody] RequestUpdateMdAddressByIdWebModel model)
    {
        return await Task.Run(() => updateMdAddressByIdWebService.Execute(model));
    }

    /// <summary>
    /// 通过编号获取收货/发货地址服务
    /// </summary>
    public GetMdAddressByIdWebService getMdAddressByIdWebService { get; set; }
    /// <summary>
    /// 通过编号获取收货/发货地址
    /// </summary>
    /// <param name="addressId">地址编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{addressId}")]
    public async Task<ResponseMessageModel> GetMdAddressByIdWeb(long addressId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetMdAddressByIdWebModel();

        model.AddressId = addressId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdAddressByIdWebService.Execute(model));
    }

    /// <summary>
    /// 分页获取收货/发货地址列表服务
    /// </summary>
    public GetMdAddressPageListWebService getMdAddressPageListWebService { get; set; }
    /// <summary>
    /// 分页获取收货/发货地址列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetMdAddressPageListWeb([FromBody] RequestGetMdAddressPageListWebModel model)
    {
        return await Task.Run(() => getMdAddressPageListWebService.Execute(model));
    }
}

